<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>千锋健康</title>
        <meta name="description" content="千锋健康">
        <meta name="keywords" content="千锋健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="plugins/elementui/index.css">
        <link rel="stylesheet" href="css/login.css">
        <script>
            if(window.self != window.top){
                window.top.location = window.location;
            }
        </script>
    </head>
    <body class="hold-transition skin-purple sidebar-mini">
        <div id="app">
            <div class="login-container">
                <div class="loginBox">
                  <form method="post" class="login-form" label-position="left">
                      <div class="title-container">
                        <div class="logoInfo clearfix">
                          <em class="logo"></em>
                        </div>
                      </div>
                      <div>
                        <span class="svg-container svg-container_login">
                          <span class="user"></span>
                        </span>
                        <input type="text" name="username" placeholder="请输入用户名" v-model="member.username" />
                      </div>
                      <div>
                        <span class="svg-container">
                          <span class="username"></span>
                        </span>
                        <input type="password" name="password" placeholder="请输入密码" v-model="member.password"/>
                      </div>
                      <input type="button" style="width:100%;margin-bottom:30px;" value="登录" @click="login"></input>
                </form>
                </div>
              </div>
        </div>
    </body>
    <!-- 引入组件库 -->
    <script src="js/vue.js"></script>
    <script src="plugins/elementui/index.js"></script>
    <script src="js/axios-0.18.0.js"></script>


    <script>
        new Vue({
            el:"#app",
            data:{
                member:{
                    username:"",
                    password:""
                }
            },
            methods:{
                login(){
                    //发送异步请求，实现登录
                    axios({
                        //security中有一个默认处理登录的资源名为login
                        url:"http://localhost:8081/login",
                        method:"post",
                        //注意参数不可以使用data携带，data携带的参时是json格式。
                        //params携带的参数是key=value&key2=value2形式
                        params:this.member
                    }).then(resp=>{
                        let result = resp.data;
                        if (result.code == 10000){
                            //登录成功：①保存token信息 ②跳转到main.html
                            let token = result.data;
                            localStorage.setItem("token",token)

                            location.href = "pages/main.html"
                        }else{
                            //登陆失败：提示用户
                            alert(result.msg)
                        }
                    });
                }
            }
        });
    </script>
</html>
